//
//  RTJChargeRootController.m
//  RuiTaiJinProject
//
//  Created by jayson on 2018/12/5.
//  Copyright © 2018年 leewei. All rights reserved.
//

#import "RTJChargeRootController.h"
#import <MXPagerView/MXPagerViewController.h>
#import "RTJChargeController.h"
#import "RTJOfflineController.h"
#import "RTJHBJXController.h"
#import "RTJJiaXiController.h"

@interface RTJChargeRootController ()<HongbaoDelegate,JiaXiDelegate>

@property (weak, nonatomic) IBOutlet UIButton *ongoingBtn;
@property (weak, nonatomic) IBOutlet UIButton *endingBtn;
@property (strong, nonatomic) IBOutlet MXPagerView *pageView;
@property (weak, nonatomic) IBOutlet UIImageView *bottomImg;

@property(nonatomic,strong) RTJHBJXController *ongoingVC;
@property(nonatomic,strong) RTJJiaXiController *endingVC;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *viewTop;

@end

@implementation RTJChargeRootController

-(void)viewDidAppear:(BOOL)animated{
    
    self.navigationController.navigationBarHidden = YES;

}

-(void)viewWillAppear:(BOOL)animated{
    
    self.navigationController.navigationBarHidden = YES;

}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.viewTop.constant = screenH > 811 ? 24 : 0; self.navigationController.navigationBarHidden = YES;
    [self initViewControllers];

}

-(void)initViewControllers{
    
    _ongoingVC=[[RTJHBJXController alloc]init];
    _ongoingVC.delegate = self;
    _ongoingVC.hongbaoArr = _hongbaoArr;
    _ongoingVC.isUserCenter = _isUserCenter;
    [self addChildViewController:_ongoingVC];
    [_ongoingVC didMoveToParentViewController:self];
    
    _endingVC=[[RTJJiaXiController alloc]init];
    _endingVC.jiaxiArr = _jiaxiArr;
    _endingVC.delegate = self;
    _endingVC.isUserCenter = _isUserCenter;
    [self addChildViewController:_endingVC];
    [_endingVC didMoveToParentViewController:self];

}

- (IBAction)buttonItemPressed:(UIButton *)sender {
    
    if (sender.tag == 10) {
        
        [self changeBtnStatu:0];
        
        [self.pageView showPageAtIndex:0 animated:YES];
        
        
    }else{
        
        [self changeBtnStatu:1];
        
        [self.pageView showPageAtIndex:1 animated:YES];
        
    }
}

#pragma mark - MXPagerViewDataSource

- (NSInteger)numberOfPagesInPagerView:(MXPagerView *)pagerView
{
    return 2;
}

- (nullable __kindof UIView *) pagerView:(MXPagerView *)pagerView viewForPageAtIndex:(NSInteger)index
{
    switch (index) {
        case 0:
            
            return _ongoingVC.view;
            
		case 1:

            return _endingVC.view;
            
            break;
    }
    
    return nil;
}


#pragma mark - MXPagerViewDelegate

- (void)pagerView:(MXPagerView *)pagerView didMoveToPageAtIndex:(NSInteger)index
{
    if (index==0) {
        
        [UIView animateWithDuration:0.5 animations:^{
            
            [self changeBtnStatu:index];
            
        } completion:^(BOOL finished) {
            
        }];
        
    }
    else if (index==1) {
        [UIView animateWithDuration:0.5 animations:^{
            
            [self changeBtnStatu:index];
            
        } completion:^(BOOL finished) {
        }];
    }
}

-(void)changeBtnStatu:(NSUInteger )index{
    
    if (index==0) {
        
        [_ongoingBtn setTitleColor:[UIColor colorForHex:@"#333333"] forState:UIControlStateNormal];
        
        _bottomImg.centerX = _ongoingBtn.centerX;
        
        [_endingBtn setTitleColor:[UIColor colorForHex:@"#999999"] forState:UIControlStateNormal];
        
        
    }else{
        
        [_endingBtn setTitleColor:[UIColor colorForHex:@"#333333"] forState:UIControlStateNormal];
        
        _bottomImg.centerX = _endingBtn.centerX;
        
        [_ongoingBtn setTitleColor:[UIColor colorForHex:@"#999999"] forState:UIControlStateNormal];
        
    }
    
}

- (IBAction)back:(id)sender {
    
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)hongBaoName:(NSString *)cardName money:(NSInteger)moeny cardId:(NSInteger)cardId min_money:(NSInteger)min_money{
    
    [self.delegate hongBaoName:cardName money:moeny cardId:cardId minMoney:min_money];
    
}

-(void)jiaxiName:(NSString *)cardName rate:(NSInteger)rate cardId:(NSInteger)cardId min_money:(NSInteger)min_money{
    
    [self.delegate JiaxiName:cardName rate:rate cardId:cardId minMoney:min_money];
}




@end
